package com.xiguaji.tiktok.v1.ins.dic.controller;

import com.xiguaji.tiktok.config.exception.ParamsException;
import com.xiguaji.tiktok.utils.Ret;
import com.xiguaji.tiktok.v1.InsBaseController;
import com.xiguaji.tiktok.v1.ins.dic.service.DicService;
import com.xiguaji.tiktok.v1.user.log.Operation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
@Api(value = "ins字典",tags = {"ins字典"})
public class DicController extends InsBaseController {
    @Autowired
    DicService dicService;

    @ApiOperation(value = "获取国家列表")
    @RequestMapping(value = "dic/region",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    @Operation(value = "获取国家列表")
    public String getRegionList(String data) throws UnsupportedEncodingException, ParamsException {
        Integer type = null;
        if(!StringUtils.isEmpty(data)){
            type = getParam(Integer.class, URLDecoder.decode(data,"UTF-8"),"type");
        }
        return Ret.success("success",dicService.getNations(type));
    }

    @ApiOperation(value = "获取语言列表")
    @RequestMapping(value = "dic/language",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    @Operation(value = "获取语言列表")
    public String getLanguageList(String data) throws UnsupportedEncodingException, ParamsException {
        Integer type = null;
        if(!StringUtils.isEmpty(data)){
            type = getParam(Integer.class, URLDecoder.decode(data,"UTF-8"),"type");
        }
        return Ret.success("success",dicService.getLanguage(type));
    }

    @ApiOperation(value = "第一分类列表")
    @RequestMapping(value = "dic/overall/category", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @Operation(value = "第一分类列表")
    public String getOverallCategory(){
        return Ret.success("success",dicService.getOverallCategory());
    }

    @ApiOperation(value = "第二分类列表")
    @RequestMapping(value = "dic/category", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @Operation(value = "第二分类列表")
    public String getCategoryByOverallCategory(String data) throws UnsupportedEncodingException, ParamsException {
        String overall = getParam(String.class, URLDecoder.decode(data,"UTF-8"),"overallCategory");
        return Ret.success("success",dicService.getCategoryByOverallCategory(overall));
    }

    @ApiOperation(value = "商业类列表")
    @RequestMapping(value = "dic/commercial/category", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @Operation(value = "商业类列表")
    public String getCommercialCategory(){
        return Ret.success("success",dicService.findCommercialCategory());
    }
}
